import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;

public class DistributionCalculator {
	
	public static Map<String, Integer> calculate(Reader r, int n, int length) throws IOException {
		StringBuilder b = new StringBuilder();
		int j = 0;
		while(j <= length && r.ready()) {
			b.append((char) r.read());
			j++;
		}
		String s = b.toString();
		Map<String, Integer> map = new HashMap<String, Integer>();
		for (int i = 0; i < s.length() - n; i++) {
			String key = s.substring(i, i + n);
			if (!map.containsKey(key)) {
				map.put(key, 1);
			} else {
				map.put(key, map.get(key) + 1);
			}
		}
		return map;
	}
	
	private static void writeOutput(Map<String, Integer> map, Writer w) throws IOException {
		w.append(String.format("%d\n", map.values().size()));
		for (Integer i : map.values()) {
			w.append(String.format("%d\n", i));
		}
	}
	
	public static void main(String[] args) throws IOException {
		final int length = 125179;
		
		for (int i = 1; i <= 4; i++) {
			Reader r = new BufferedReader(new FileReader("../../asyoulik.txt"));
			Writer w = new FileWriter(String.format("../../probabs-%d.txt", i));
			writeOutput(calculate(r, i, length), w);
			w.close();
			r.close();
		}
	}
}
